package com.xiaominfo.oss.utils;

import java.util.Random;

/**
 * @Author lien
 * @Date 2019/12/24 16:57
 * @Description 随机工具类
 **/
public class RandomUtils {

    private static String[] ens=new String[]{"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};

    private static int[] arr=new int[]{0,1,2,3,4,5,6,7,8,9};


    /**
     * 随机生成指定位数的字符串（字母全部小写）
     * @param len
     * @return
     */
    public static String random(int len){
        StringBuffer str=new StringBuffer();
        for (int i=0;i<len;i++){
            int x=new Random().nextInt(ens.length);
            if (x%2==0){
                //字母
                str.append(ens[x].toLowerCase());
            }else{
                //数字
                x=new Random().nextInt(arr.length);
                str.append(arr[x]);
            }
        }
        return str.toString();
    }
    public static void main(String[] args) {
        System.out.println(random(6));

    }
}
